package com.duowei.kitchenshow.adapter;

import android.text.TextUtils;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.duowei.kitchenshow.R;
import com.duowei.kitchenshow.app.MyApp;
import com.duowei.kitchenshow.bean.Cfpb;
import com.duowei.kitchenshow.bean.Cfpb_item;
import com.duowei.kitchenshow.sound.KeySound;

import java.util.List;

public class RvLeftAdapter extends BaseQuickAdapter<Cfpb> {
    int layout;
    private final KeySound mSound;

    public RvLeftAdapter(int layoutResId, List<Cfpb> data) {
        super(layoutResId, data);
        this.layout=layoutResId;
        mSound = KeySound.getContext(MyApp.getContext());
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, Cfpb cfpb) {
        baseViewHolder.setText(R.id.tv_time,cfpb.getFzs()+"分钟");
        if(layout==R.layout.leftadapter_item){//按菜品分类
            baseViewHolder.setText(R.id.tv_name,cfpb.getXmmc()+"\n"+cfpb.getPz());
        }else{//按餐桌分类
            baseViewHolder.setText(R.id.tv_name,cfpb.getCzmc());
        }
        List<Cfpb_item> itemList = cfpb.getItemList();
        baseViewHolder.setText(R.id.tv_num,getSl(itemList)+"份");

        //超时单品
        String cssj = cfpb.getCssj();
        if(cfpb.isClick()){
            if(layout==R.layout.leftadapter_item){//菜品颜色
                if(!TextUtils.isEmpty(cssj)&&cfpb.getFzs()>Integer.parseInt(cssj)){//超时
                    baseViewHolder.setBackgroundRes(R.id.rl_left,R.drawable.shape_outtime_click);
                }else{
                    baseViewHolder.setBackgroundRes(R.id.rl_left,R.drawable.shape_yellow_click);
                }
            }else{//餐桌颜色
                baseViewHolder.setBackgroundRes(R.id.rl_left,R.drawable.shape_blue_click);
            }
        }else{
            if(layout==R.layout.leftadapter_item){//菜品颜色
                if(!TextUtils.isEmpty(cssj)&&cfpb.getFzs()>Integer.parseInt(cssj)){//超时
                    baseViewHolder.setBackgroundRes(R.id.rl_left,R.drawable.shape_outtime_normal);
                }else{
                    baseViewHolder.setBackgroundRes(R.id.rl_left,R.drawable.shape_yellow_normal);
                }
            }else{//餐桌颜色
                baseViewHolder.setBackgroundRes(R.id.rl_left,R.drawable.shape_blue_normal);
            }
        }

//        if("1".equals(cfpb.getSfyxzz())){
//            mSound.playSound('2',0);
//        }
    }

    private float getSl(List<Cfpb_item> itemList) {
        float sum=0;
        for(Cfpb_item item:itemList){
            sum+=item.sl1;
        }
        return sum;
    }
}
